<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="com.boxin.framework.base.utils.DateUtils"%>
<%@page import="com.thinkgem.jeesite.modules.sys.utils.UserUtils"%>
<%@page import="com.thinkgem.jeesite.modules.sys.entity.User"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.google.zxing.Result"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="com.boxin.framework.base.dao.DaoHelper"%>
<%@page import="com.boxin.ims.modules.wechat.utils.SpringUtils"%>
<%@page import="com.boxin.ims.modules.wechat.service.WechatDaoHelper"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>统计管理</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>

	<%
		DaoHelper daoHelper = (DaoHelper)SpringUtils.getBean("daoHelper");
		DataSource dataSource =  daoHelper.getIbatisTemplate().getSqlMapClientTemplate().getDataSource();
		Connection conn = 	dataSource.getConnection();
		String sql ="select * from wp_wechat_member";
		String endTime  = request.getParameter("endTime");
		String startTime = request.getParameter("startTime");
		if(StringUtils.isEmpty(startTime)){
			startTime=DateUtils.formatDate(new Date(), "yyyy-mm-dd HH:MM:ss");
		}
		User user = UserUtils.getUser();
		Long userId = user.getId();
		sql ="SELECT user_id ,NAME,STATUS,COUNT(1) cnt FROM wp_lottery_record WHERE user_id= ? AND  update_time >= ?	 GROUP BY user_id,NAME,STATUS";
				
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setLong(1, userId);
		pstmt.setString(2, startTime);
		ResultSet rs = pstmt.executeQuery();
		int i=1;
		
		
		
	%>
		


	<ul class="nav nav-tabs">
		<li class="active"><a href="javascript:void();">会员统计</a></li>
	</ul>
	<form id="searchForm"   action="lotteryStatics.jsp" method="post" class="breadcrumb form-search">
		
		<label>手机号 ：</label><input type="text" name="mobile" />
		<label>开始结束 ：</label>
					<input id="startTime" name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value=""
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
						
		<label>结束时间 ：</label>
					<input id="endTime" name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value=""
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
						
		&nbsp;&nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
	</form>
	<tags:message content="${message}"/>
	
 	
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr>
			<th>奖品名称</th>
			<th>状态</th>
			<th>数量</th>
			</tr>
		</thead>
		<tbody>
		<%while(rs.next()){	%>
			<tr>
				<td><%=rs.getString("name")%></td>
				<td><%=rs.getString("status") %></td>
				<td><%=rs.getString("cnt") %></td>
			</tr>
		<%} 
			try{
				conn.close();
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		%>
		</tbody>
	</table>
</body>
</html>
